package com.ruoyi.project.park.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.lang.Snowflake;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.park.domain.BizMonitor;
import com.ruoyi.project.park.service.IBizMonitorService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 停车场监控Controller
 * 
 * @author ruoyi
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/park/monitor")
public class BizMonitorController extends BaseController
{
    @Autowired
    private IBizMonitorService bizMonitorService;

    /**
     * 查询停车场监控列表
     */
    @PreAuthorize("@ss.hasPermi('park:monitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizMonitor bizMonitor)
    {
        startPage();
        List<BizMonitor> list = bizMonitorService.selectBizMonitorList(bizMonitor);
        return getDataTable(list);
    }

    /**
     * 导出停车场监控列表
     */
    @PreAuthorize("@ss.hasPermi('park:monitor:export')")
    @Log(title = "停车场监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizMonitor bizMonitor)
    {
        List<BizMonitor> list = bizMonitorService.selectBizMonitorList(bizMonitor);
        ExcelUtil<BizMonitor> util = new ExcelUtil<BizMonitor>(BizMonitor.class);
        util.exportExcel(response, list, "停车场监控数据");
    }

    /**
     * 获取停车场监控详细信息
     */
    @PreAuthorize("@ss.hasPermi('park:monitor:query')")
    @GetMapping(value = "/{monitorId}")
    public AjaxResult getInfo(@PathVariable("monitorId") String monitorId)
    {
        return AjaxResult.success(bizMonitorService.selectBizMonitorByMonitorId(monitorId));
    }

    /**
     * 新增停车场监控
     */
    @PreAuthorize("@ss.hasPermi('park:monitor:add')")
    @Log(title = "停车场监控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizMonitor bizMonitor)
    {
        //生成雪花id
        String nextIdStr = new Snowflake(1, 1).nextIdStr();
        bizMonitor.setMonitorId(nextIdStr);
        return toAjax(bizMonitorService.insertBizMonitor(bizMonitor));
    }

    /**
     * 修改停车场监控
     */
    @PreAuthorize("@ss.hasPermi('park:monitor:edit')")
    @Log(title = "停车场监控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizMonitor bizMonitor)
    {
        return toAjax(bizMonitorService.updateBizMonitor(bizMonitor));
    }

    /**
     * 删除停车场监控
     */
    @PreAuthorize("@ss.hasPermi('park:monitor:remove')")
    @Log(title = "停车场监控", businessType = BusinessType.DELETE)
	@DeleteMapping("/{monitorIds}")
    public AjaxResult remove(@PathVariable String[] monitorIds)
    {
        return toAjax(bizMonitorService.deleteBizMonitorByMonitorIds(monitorIds));
    }
}
